package com.hypo.business.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hypo.business.domain.po.Pcd;
import com.hypo.business.domain.vo.PcdVo;
import com.hypo.business.mapper.PcdMapper;
import com.hypo.business.service.PcdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 省市区Service业务层处理
 *
 * @author ruoyi
 * @date 2025-08-03
 */
@Service
public class PcdServiceImpl extends ServiceImpl<PcdMapper,Pcd> implements PcdService
{
    @Autowired
    private PcdMapper pcdMapper;

    @Override
    public List<PcdVo> getAll() {
        List<PcdVo> all = pcdMapper.getAll();
        List<PcdVo> fu = all.stream().filter(s -> s.getParentId().equals(0)).toList();
        fu.forEach(s->setZiList(s,all));
        return fu;
    }

    private void setZiList(PcdVo fu,List<PcdVo> all){
        List<PcdVo> ziList = all.stream().filter(s -> s.getParentId().equals(fu.getValue())).toList();
        fu.setChildren(ziList);
        ziList.forEach(s->setZiList(s,all));
    }
}

